class Base {
	//吐司
	toast(title, icon, duration) {
		if (title) {
			uni.showToast({
				title: title,
				icon: icon ? icon : 'none',
				duration: duration ? duration : 2000
			})
		}
	}
	//跳转
	navigateTo(url) {
		uni.navigateTo({
			url: url
		})
	}
	////跳转
	redirectTo(url) {
		uni.redirectTo({
			url: url
		})
	}
	////跳转
	reLaunch(url) {
		uni.reLaunch({
			url: url
		})
	}
	
	//检测是否登录
	checkYz(value,message) {
		if (value) {
			return true;
		}else{
			this.toast(message)
			return false
		}
	}
	//检测是否登录
	checkPhone(value) {
		if (value) {
			if(value.length==11){
				return true;
			}else{
				this.toast('手机号格式不正确')
				return false;
			}
		}else{
			this.toast('请输入手机号')
			return false
		}
	}
	//检测是否登录
	checkUser() {
		if (!uni.getStorageSync('token')) {
			return false
		}
		return true;
	}
	//检测是否登录
	checkUserToLogin() {
		if (!uni.getStorageSync('token')) {
			uni.navigateTo({
				url: '/pages/login/login'
			})
			return false
		}
		return true;
	}

	//检测是否登录
	checkUserDialog() {
		if (!uni.getStorageSync('token')) {
			uni.showModal({
				title: '提示',
				content: '您尚未登录，是否去登录！',
				success: function(res) {
					if (res.confirm) {
						console.log(res)
						uni.navigateTo({
							url: '/pages/login/login'
						})
					}
				}
			})
			return false
		}
		return true;
	}
}

const base = new Base()
export default base
